congratulations your first lesson in debugging - look through you code and find where you would get the value -32. forget about what values variables are suposed to be.
also, the inner set of {} is unnecessary
edit: scribbler beat me to this
congratulations your first lesson in debugging - look through you code and find where you would get the value -32. forget about what values variables are suposed to be.
also, the inner set of {} is unnecessary
edit: scribbler beat me to this
i seem to have GCC 3.3.4
But how do i start it?
I dont have a menu for it or anything.
I believe your problem is right on this line: float b = ( 5/9 * a - 32 ) ;
More precisly 5/9, that is integer division and it is my bet that this is evaluated to 0, so basicly your expression looks like this:
float b = ( 0 * a - 32 ) ;
To fix you have to make sure you tell the compiler that you dont want integer division, by doing this: float b = ( 5.0f/9.0f * a - 32 ) ;
The trailing f is just to tell the compiler its a float and not a double.
Edit: awwwwww beaten!
I got it, finaly, thanks
actually, it was that i didnt have "()" around "a - 32", it did the multiplication first, thats why I got that answer
Code:#include <iostream> using namespace std; int main() { int a; cout<<"Enter Farenheit temperature to convert to Celcius:\n"; cin>> a; float b = (5.0/9.0 * (a - 32) ) ; cin.ignore(); { cout<<"Your answer is:"<< b <<"\n"; } cin.get(); }
i doubt that. the output was -32 every time. what possible values are in the expression (n * m - 32) in which return the value -32? we know that changing 'm' does not effect the outcome, so we have (n * const value - 32). n = 5/9. if n is evalutated as an integer, then n = 0. which makes (0 * const value - 32). (0 * any number - 32) is always - 32.Originally Posted by futurama140
i seem to have GCC 3.3.4
But how do i start it?
I dont have a menu for it or anything.
Both were problem. Solving only the first part would have resulted in values that actually depend on the input, but they would have been false. Solving only the second part would have resulted in 0 always being the output instead of -32.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law